<Widget:show bdcls="no-padding" col="12" title="" >
    <Widget:action >
    &nbsp;&nbsp;
    <a class="btn btn-sm red" data-pjax href="{:U("Db/tbinfo?f=$f")}">返回</a>

    <a class="btn btn-sm purple" ajax-dialog href="{:U("Index/editItem?f=$f")}">项目信息</a>
    <a class="btn btn-sm purple" ajax-dialog href="{:U("DB/addField?tb=$tb&f=$f")}">新增字段</a>

    <a class="btn btn-sm blue" href="{:U("Db/opt?tb=$tb&setup=analyze")}">分析</a>
    <a class="btn btn-sm blue" href="{:U("Db/opt?tb=$tb&setup=optimize")}">优化</a>
    <a class="btn btn-sm blue" href="{:U("Db/opt?tb=$tb&setup=check")}">检查</a>
    <a class="btn btn-sm blue" href="{:U("Db/opt?tb=$tb&setup=repair")}">修复</a>
    <a class="btn btn-sm blue" href="{:U("Db/opt?tb=$tb&setup=truncate")}">清空</a>

    <a class="btn btn-sm green" data-ajax href="{:U("Db/design?tb=$tb&f=$f&t=true")}">生成表单</a>
    <a class="btn btn-sm green" data-ajax href="{:U("Db/creatC?name=$tb&f=$f")}">生成控制器</a>
    <a class="btn btn-sm green" data-ajax href="{:U("Db/creatM?name=$tb&f=$f")}">生成模型</a>
    <a class="btn btn-sm green" data-pjax href="{:U("Db/design?tb=$tb&f=$f")}">设计表单</a>
    <a class="btn btn-sm btn-default " ajax-dialog href="{:U("DB/document?tb=$tb&f=$f")}">文档</a>
    </Widget:action>

    <Widget:action >
    <select data-value="{$Think.get.tb}" name="tb" class="form-control input-sm" >
        <volist name="tables" id="tt">
            <option value="{$tt.table_name}">{$tt.table_name}</option>
        </volist>
    </select>
    </Widget:action>


    <div class="table-scrollable">
        <table class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th>字段名</th>
                <th>类型</th>
                <th>长度</th>
                <th>选项</th>
                <th>NULL</th>
                <th>AI</th>
                <th>默认值</th>
                <th>注释</th>
                <th width="100">#</th>
            </tr>
        </thead>
        <volist name="table" id="tbs">
        <tr>
            <td>{$tbs.field}</td>
            <td>
                <select data-value="{$tbs[type]}" name="type">
                    {:fieldTypeOpt()}
                </select>
            </td>
            <td><a data-editable data-pk="{$tbs.field}" data-name="length" href="#">{$tbs.length}</a></td>
            <td>
                <in name="tbs[type]" value="varchar" >
                {:fieldCollationOpt($tbs[collation])}
                </in>
            </td>
            <td>
            <neq name="tbs[primary]" value="PRI" >
            <input type="checkbox" data-name="isnull" data-pk="{$tbs.field}" name="isnull" <eq name="tbs[isnull]" value="YES" >checked</eq>  />
            </neq>
            </td>
            <td><eq name="tbs[primary]" value="PRI" >YES</eq></td>

            <td>
            <a data-editable data-name="default" data-pk="{$tbs.field}" href="#">{$tbs.default}</a>
            </td>
            <td>
            <a data-editable data-name="comment" data-pk="{$tbs.field}" href="#">{$tbs.comment}</a>
            </td>
            <td>
                <neq name="tbs[pos]" value="$table_count">
                <a data-pk="{$tbs.field}" data-arrow="moveDown" href="#"><i class="glyphicon glyphicon-arrow-down"></i></a>
                </neq>
                <neq name="tbs[pos]" value="0">
                <a data-pk="{$tbs.field}" data-arrow="moveUp" href="#"><i class="glyphicon glyphicon-arrow-up"></i></a>
                </neq>
                <a data-ajax href="{:U("Table/deleteField?tb=$tb&field=$tbs[field]&f=$f")}"><i class="glyphicon glyphicon-remove"></i></a>
            </td>
        </tr>
        </volist>
        </table>
    </div>
</Widget:show>


<script type="text/javascript">
    $(function(){
        var url = "{:U("Db/updateField?f=$f&tb=$tb")}";
        $.fn.editable.defaults.url = url;
        $('[data-editable]').editable();
        $('[name=isnull]').on('click',function(){
            var pk = $(this).attr('data-pk');
            var value = 'NO';
            if ($(this).prop('checked')) {
                value = 'YES';
            }
            $.get(url,{name:name,pk:pk,value:value});
        })



        $('[data-arrow]').on('click',function(e){
            e.preventDefault();
            var name = $(this).attr('data-arrow');
            var value = 'NO';
            var pk = $(this).attr('data-pk');
            $.get(url,{name:name,pk:pk,value:value},function(){
                var container = $('[pjax-content]');
                $.pjax.reload(container);
                // var u = window.location.href;
                // window.location.href = u;
            });
        })
    $('select[name=tb]').on('change',function(){
        var tb = $(this).val();
        var container = $('[pjax-content]');
        var url = window.location.href;
        url = U('tb',tb,url);
        $.pjax({url: url, container: container})
    })
    })
</script>
